import base64

from PIL import Image


def imgtobase64(img_path):
    pil_image = Image.open(img_path).resize((900, 600))
    base64str = base64.b64encode(pil_image)
    print(base64str)


def base64toimg(str):
    data = str.split(',')[1]
    image_data = base64.b64decode(data)
    with open('1.gif', 'wb') as f:
        f.write(image_data)
if __name__ == '__main__':
    str=""
    base64toimg(str)